package com.tanzc.mp3player.filter;

import java.io.File;
import java.io.FilenameFilter;

/**
 * <p> description: description </p>
 *
 * @author tanzc
 * @date 11:23 2021/5/21
 **/
public class FilenameSuffixFilter implements FilenameFilter {
    private String fileSuffix;

    public FilenameSuffixFilter(String fileSuffix) {
        this.fileSuffix = fileSuffix;
    }

    public String getFileSuffix() {
        return this.fileSuffix;
    }

    @Override
    public boolean accept(File dir, String name) {
        String fileType = this.getFileSuffix();
        // 如果name==suffix，则直接是一个跟后缀名同名的目录，返回false
        if (fileSuffix.equals(name)) {
            return false;
        }
        return name.endsWith(fileSuffix);
    }
}
